package orsetto;

import orsetto1vs1.Damala;
import orsettomelee.DamalaMelee;
import robocode.AdvancedRobot;
import robocode.HitByBulletEvent;
import robocode.RobotDeathEvent;
import robocode.ScannedRobotEvent;

public class OrsettoDistruttore extends AdvancedRobot {

	private int numEnemy;
	private Boolean is1vs1;
	private static Damala orsetto1vs1;
	private static DamalaMelee orsettoMelee;

	public OrsettoDistruttore() {
		if (orsetto1vs1 == null)
			orsetto1vs1 = new Damala(this);
	}

	@Override
	public void run() {
		numEnemy = 0;
		turnRadarLeft(360);
		out.println(numEnemy);
		if (numEnemy > 1) {
			is1vs1 = false;
			orsettoMelee = new DamalaMelee(this);
			orsettoMelee.runMelee();
		} else {
			is1vs1 = true;
			orsetto1vs1.run1vs1();
		}

	}

	@Override
	public void onScannedRobot(ScannedRobotEvent event) {
		if (is1vs1 == null) {
			numEnemy++;
			return;
		}
		if (is1vs1)
			orsetto1vs1.onScannedRobot1vs1(event);
		else
			orsettoMelee.onScannedRobotMelee(event);
	}

	@Override
	public void onHitByBullet(HitByBulletEvent event) {
		if (is1vs1)
			orsetto1vs1.onHitByBullet1vs1(event);
	}

	@Override
	public void onRobotDeath(RobotDeathEvent event) {
		if (!is1vs1)
			orsettoMelee.onRobotDeathMelee(event);
	}
}
